<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Goodscommon extends Model
{
    protected $connection = 'database.cheat';
    // 表名
    protected $table = 'goods_common';
    use SoftDelete;
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime='deletetime';
    // 追加属性
    protected $append = [
       // 'deletetime_text'
        'status_text',
        'goods_verify_text',
        'source_text',
        'is_recomment_text'
    ];
    
    public function getStatusList(){
        return ['1' => __('Status 1'),'2' => __('Status 2'),'3' => __('Status 3')];
    }
    public function getGoodsVerifyList(){
        return ['1' => __('Goods_verify 1'),'2' => __('Goods_verify 2'),'3' => __('Goods_verify 3')];
    }
    public function getSourceList(){
        return ['1' => __('Source 1'),'2' => __('Source 2')];
    }
    public function getIsRecommentList(){
        return ['1' => __('Is_recomment 1'),'2' => __('Is_recomment 2')];
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getGoodsVerifyTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['goods_verify']) ? $data['goods_verify'] : '');
        $list = $this->getGoodsVerifyList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getSourceTextAttr($value, $data)
    {
    $value = $value ? $value : (isset($data['source']) ? $data['source'] : '');
    $list = $this->getSourceList();
    return isset($list[$value]) ? $list[$value] : '';
    }
    public function getIsRecommentTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_recomment']) ? $data['is_recomment'] : '');
        $list = $this->getIsRecommentList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    #关联店铺名
    public function store(){
        return $this->belongsTo('Storejoin','store_id','id','','LEFT')->setEagerlyType(0);
    }
   /* public function getStoreIdAttr($value){
        if($value==0){
            $value='自营';
        }
        return $value;
    }*/
   /* public function getPicAttr($value){
        $value=str_replace(SHOPURL,'',$value);
        return $value;
    }*/
}
